<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const user = {
        firstName: "chen",
        lastName: "jack",
      };

      /*
        ① value 属性没要存在了，用get（读取）和set（写入）替代
        ② get() 返回数据作为属性的值，set() 会在属性被赋值的时候触发
        ③ get 和 set 中 this 指向 . 前面的对象
        ③ writable标志无效，  enumerable,configurable 正常使用
      */
      Object.defineProperty(user, "fullName", {
        get() {
          return `${this.lastName} ${this.firstName}`;
        },
        set(value) {
          [this.lastName, this.firstName] = value.split(" ");
        },
      });

      console.log(user.fullName);
      user.fullName = "lili zhang";
      console.log(user.fullName);
    </script>
  </body>
</html>
